using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using System.Runtime.CompilerServices;

namespace DA.AnimGraph {
    public unsafe static class NativeExtension {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static ref T GetRefAt<T>(this NativeArray<T> self, int index) where T : unmanaged {
            return ref UnsafeUtility.ArrayElementAsRef<T>(self.GetUnsafeReadOnlyPtr(), index);
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static T* GetPtrAt<T>(this NativeArray<T> self, int index) where T : unmanaged {
            return (T*)UnsafeUtility.AddressOf(ref UnsafeUtility.ArrayElementAsRef<T>(self.GetUnsafeReadOnlyPtr(), index));
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static ref T GetRefAt<T>(this UnsafeList<T> self, int index) where T : unmanaged {
            return ref UnsafeUtility.ArrayElementAsRef<T>(self.Ptr, index);
        }
    }
}
